package presenter;

import java.util.HashMap;

import model.base.Model;

public class UserCommands {

	private  HashMap<String, Command> commands = new HashMap<String, Command>();		// HMap that links between Strings and instances of classes that implement specific commands
	public UserCommands() {	// C'tor
		commands.put("SelectDomain", new SelectDomainCommand());		// initializing the HMap
		commands.put("SelectAlgorithm", new SelectAlgorithmCommand());
		commands.put("SolveDomain", new SolveDomainCommand());
	}
	
	public void doCommand(Model model, String commandName, String argument){		// the func holds a local instance of Command interface (bellow)
		Command command = commands.get(commandName);								// and matches "commandName" to commands HMap to link  the right Command implementing class instance
		if (command != null)													 
			command.doCommand(model, argument);
	}
	
////////////////////////////////////////////////////////////////////////
	
	public interface Command{							// Command interface
		void doCommand(Model model, String args);
	}
	
	private class SelectDomainCommand implements Command{			// the command SelectDomainCommand is sort of a Command and operates selectDomain method
		@Override
		public void doCommand(Model model, String domainNamePlusStartingState) {
			model.selectDomain(domainNamePlusStartingState);			
		}
	}
	
	private class SelectAlgorithmCommand implements Command{		// same comment other operation
		@Override
		public void doCommand(Model model, String algorithmNamePlusHeuristic) {
			model.selectAlgorithm(algorithmNamePlusHeuristic);
		}
	}
	
	private class SolveDomainCommand implements Command{			// same
		@Override
		public void doCommand(Model model, String args) {
			model.solveDomain();			
		}
	}

}
